﻿using System;
using System.Web.Mvc;
using Micua.Core.Configuration;
using Micua.Model.Struct;
using Micua.Utility;

namespace Micua.UI.Result
{
    public class MicuaHttpNotFoundResult : HttpNotFoundResult
    {
        public MicuaHttpNotFoundResult() : this(null) { }

        public MicuaHttpNotFoundResult(string statusDescription) : base(statusDescription) { }

        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            context.HttpContext.Response.StatusCode = this.StatusCode;
            if (this.StatusDescription != null)
            {
                context.HttpContext.Response.StatusDescription = this.StatusDescription;
            }
            var result = new ViewResult
            {
                ViewName = "Error"
            };
            result.ViewBag.Error = "NotFound".GetCultureString(Setting.GetString(OptionKeys.SiteCulture));
            //HttpContext.ExceptionHandled = true;
            context.HttpContext.Response.Clear();
            context.HttpContext.Response.StatusCode = 404;
            context.HttpContext.Response.TrySkipIisCustomErrors = true;
            result.ExecuteResult(context);
        }
    }
}